package com.iweb.controller;


import com.common.context.RequestMapping;
import com.iweb.pojo.Strategy;
import com.iweb.service.StrategyService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Random;

@RequestMapping("Strategy")
public class StrategyController {

    @RequestMapping("selectStrategyList")
    public String selectStrategy(Strategy strategy, HttpServletRequest request){

        StrategyService strategyService = new StrategyService();

        String title = null;

        if (strategy!=null){
            title = strategy.getTitle();
        }

        List<Strategy> list = strategyService.selectStrategyList(title);
        int len = list.size();
        for (int i = 0; i < 10-len; i++) {
            list.add(list.get(new Random().nextInt(list.size())));
        }
        request.setAttribute("list",list);
        return "/Strategy/list.jsp";
    }

    @RequestMapping("selectById")
    public String selectById(Strategy strategy, HttpServletRequest request) {

        StrategyService strategyService = new StrategyService();

        String title = null;

        if (strategy!=null){
            title = strategy.getTitle();
        }

        List<Strategy> detail = strategyService.selectStrategyList(title);
        request.setAttribute("detail",detail);
        return "/Strategy/detail.jsp";
    }
}
